package cn.com.sbell.vss.csg.vsclient.hikvision;

import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import cn.com.sbell.vss.VssConstants;
import cn.com.sbell.vss.VssException;

/**
 * @author liang.a.chen
 */
public class HikVisionPtzCommandSet {
	
	private static Map commandMap;
	
	static{
		commandMap = Collections.synchronizedMap(new HashMap());
		Properties prop = new Properties();
		try {
			prop.load(HikVisionPtzCommandSet.class.getResourceAsStream("HikVisionPtzCommandSet.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		Enumeration nameEnum = prop.propertyNames();
		while(nameEnum.hasMoreElements()){
			String property = (String) nameEnum.nextElement();
			Integer value = null;
			try{
				value = new Integer(prop.getProperty(property));
			}catch(Exception e){
				
			}
			commandMap.put(property, value);
		}
	}
	
	public static int getPtzCommand(String ptzcmd){
		Integer command = (Integer)commandMap.get(ptzcmd);
		if(command == null){
			throw new VssException(VssConstants.CODE_UNSUPPORTED_PTZ_PROTOCOL_COMMAND);
		}
		return command.intValue();
	}
	
	public static void main(String[] args){
		System.out.println(HikVisionPtzCommandSet.getPtzCommand("ZIN"));
		System.out.println(HikVisionPtzCommandSet.getPtzCommand("ZOUT"));
		System.out.println(HikVisionPtzCommandSet.getPtzCommand("ISTxx"));
	}
}
